/**
 * Created by meiguizhinian on 2018/7/9
 * Copyright © 2018 lixiaolong. All rights reserved.
 */

//cocos2dx class
unblockme.OverScene = LLScene.extend({
	res : [
		"res/game/UnblockMe/NETDATA/ANIMATION/Over.actor",

		"res/game/UnblockMe/vfs/bg_brown.png",
		"res/game/UnblockMe/vfs/three_stars_black.png",
		"res/game/UnblockMe/vfs/three_stars_gold.png",
	],
	ctor: function (form, space=null) {
		this._super(form, space);
		this._stars = 0;

		let button_play = this._formNode.getChildByName("bt1");
		button_play.setTouchEndCallback(function() {
			let progress = unblockme.Recorder.getProgress();
			if (progress>=unblockme.Recorder.getGateSize()) {//已经是最后一关，进入选关界面
				cc.LoaderScene.preload(unblockme.GateScene.prototype.res, function () {
					let scene = unblockme.GateScene.create("Gate");
					cc.director.runScene(scene);
				}, this);
				return;
			}
			cc.LoaderScene.preload(unblockme.GameScene.prototype.res, function () {
				let scene = unblockme.GameScene.create("Game");
				scene.select(progress);
				cc.director.runScene(scene);
			}, this);
		});
		let button_menu = this._formNode.getChildByName("bt2");
		button_menu.setTouchEndCallback(function() {
			cc.LoaderScene.preload(unblockme.GateScene.prototype.res, function () {
				let scene = unblockme.GateScene.create("Gate");
				cc.director.runScene(scene);
			}, this);
		});
		let button_replay = this._formNode.getChildByName("bt3");
		button_replay.setTouchEndCallback(function() {
			cc.LoaderScene.preload(unblockme.GateScene.prototype.res, function () {
				let scene = unblockme.GameScene.create("Game");
				let p = unblockme.Recorder.getProgress()-1;
				unblockme.Recorder.setProgress(p);
				scene.select(p);
				cc.director.runScene(scene);
			}, this);
		});
		LLNodeHelper.registerAudioButton(this._formNode, "bt4");
	},

	setStars : function(stars) {
		this._stars = stars;
		switch (stars) {
			case 4: {

			}
			case 3: {
				let node = this._formNode.getChildByName("or6");
				node.setVisible(true);
			}
			case 2: {
				let node = this._formNode.getChildByName("or5");
				node.setVisible(true);
			}
			case 1: {
				let node = this._formNode.getChildByName("or4");
				node.setVisible(true);
			}
			default:
				break;
		}
	},
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	_stars : 0,
});

unblockme.OverScene.create = function (form, space=null) {
	return new unblockme.OverScene(form, space);
};
